pp108 : Using the Custom XSLT Function

Using the Custom XSLT Function

The Custom XSLT function is used to embed custom XSLT in the data transformations. While you can use the functions and instructions provided by platform, you can also define your custom XSLT and use them in the data maps. However, you must ensure to follow the XSLT standards while defining the custom functions. Based on the XSLT provided, the target node structure will be created.

The following sections describe the usage of this Custom XSLT function in various scenarios:

  1. Access the Data Transformation Modeler () to create a data transformation model. The Data Transformation modeler page is displayed.
  2. Drag the source schema from the project tree to the Source pane of the Modeler tab. The schema instance of the Source is displayed on the modeler.
  3. Drag the target schema to the Target pane of the Modeler tab. The schema instance of the Target is displayed on the modeler.
  4. Right-click the Map Canvas(middle) pane of the Modeler tab and select Functions > Advanced > Custom XSLT. The Custom XSLT icon appears on the Map canvas.
  5. Click Custom XSLT. The properties table of the Custom XSLT is displayed at the bottom.
    You must provide the Custom XSLT content along with the root node xsl:template as shown below:
<xsl:template xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <!-- Custom XSLT content is given here -->
</xsl:template>
  • Ensure to provide proper XPaths in the XSLT to create the correct target node structure.
  • To view the XPath of the source or target element, right-click the required element and click Show XPath option in the context menu. The complete path of the element from the root node is displayed in the dialog box that appears.
  • Always ensure to use absolute XPath when the source context is not selected. You can provide a relative XPath when the source context is selected.
  • Process Platform supports XPATH 1.0 specifications. However, refer to features in Process Platform that are not supported and limitations, for information on the list of features in Process Platform that are not supported and limitations respectively.

The following scenarios demonstrate some of the usages of Custom XSLT through samples:

Scenario 1: Creating repeated target elements based on multiple source elements without linking from Source

Multiple source elements will be mapped to repeated target element.

Source Schema
<element name="Company" xmlns="http://www.w3.org/2001/XMLSchema">
    <complexType>
        <sequence>
            <element maxOccurs="unbounded" name="Employee">
                <complexType>
                    <sequence>
                        <element name="Mobile">
                            <complexType>
                                <sequence>
                                    <element name="Home"
                                    type="xs:string" xmlns:xs="http://www.w3.org/2001/XMLSchema"/>
                                    <element name="Office"
                                    type="xs:string" xmlns:xs="http://www.w3.org/2001/XMLSchema"/>
                                </sequence>
                            </complexType>
                        </element>
                    </sequence>
                </complexType>
            </element>
        </sequence>
    </complexType>
</element>

Target Schema
<element xmlns="http://www.w3.org/2001/XMLSchema" name="Team"> <complexType> <sequence> <element name="Employee" maxOccurs="unbounded"> <complexType> <sequence> <element xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsd="http://www.w3.org/2001/XMLSchema" type="xs:string" name="Mobile" maxOccurs="unbounded" /> </sequence> </complexType> </element> </sequence> </complexType> </element> </sequence> </complexType> </element>
  1. Do the following to map the elements between the source and target templates using the Custom XSLT function:
    1. Select Custom XSLT and click Team\Employee\Mobile in the Target pane.
    2. Complete XPath of the source element should be given in the XSLT as no source context is selected.
    3. Double-click Custom XSLT icon to open the properties pane and provide the following XSLT.
      <xsl:template xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
          <Mobile>
              <xsl:value-of select="/Company/Employee/Mobile/Home"/>
          </Mobile>
          <Mobile>
              <xsl:value-of select="/Company/Employee/Mobile/Office"/>
          </Mobile>
      </xsl:template>
      


  2. Click the Test Model tab. The Test Model tab with the source XML is displayed.
  3. In the Source XML pane, type appropriate values for the source elements. Alternatively, you may click Fill Source Data, which assigns sample string values to the source elements. Make changes to these values, if required. The elements in the Source XML pane are populated with the specified values.
  4. Click Transform to start the data transformation process.

The data is transformed and displayed in the Transformed XML pane indicating the completion of the process as shown below:

Test Source XML
<Company>
    <Employee>
        <Mobile>
            <Home>987654321</Home>
            <Office>987654367</Office>
        </Mobile>
    </Employee>
</Company>
Generated Target XML
<Team>
    <Employee>
        <Mobile>987654321</Mobile>
        <Mobile>987654367</Mobile>
    </Employee>
</Team>

Scenario 2: Creating an element under repeated target node linking from Source

Only one target element is created

Source Schema 2
<element name="Catalog" xmlns="http://www.w3.org/2001/XMLSchema">
    <complexType>
        <sequence>
            <element name="Products">
                <complexType>
                    <sequence>
                        <element maxOccurs="unbounded" minOccurs="0" name="Product">
                            <complexType>
                                <sequence>
                                    <xsd:element name="ProductId"
                                    type="xsd:string" xmlns:xsd="http://www.w3.org/2001/XMLSchema"/>
                                    <xsd:element
                                    name="ProductDescription"
                                    type="xsd:string" xmlns:xsd="http://www.w3.org/2001/XMLSchema"/>
                                </sequence>
                            </complexType>
                        </element>
                    </sequence>
                </complexType>
            </element>
        </sequence>
    </complexType>
</element>

Target Schema 2
<element name="PurchaseOrder" xmlns="http://www.w3.org/2001/XMLSchema">
    <complexType>
        <sequence>
            <element name="Items">
                <complexType>
                    <sequence>
                        <element maxOccurs="unbounded" minOccurs="0" name="Item">
                            <complexType>
                                <sequence>
                                    <xsd:element name="ItemCode"
                                    type="xsd:string" xmlns:xsd="http://www.w3.org/2001/XMLSchema"/>
                                    <element name="ItemDescription"
                                    type="xs:string"
                                    xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsd="http://www.w3.org/2001/XMLSchema"/>
                                </sequence>
                            </complexType>
                        </element>
                    </sequence>
                </complexType>
            </element>
        </sequence>
    </complexType>
</element>
  1. Do the following to map the elements between the source and target templates using the Custom XSLT function:
    1. Select Custom XSLT and click PurchaseOrder/Items/Item/ItemCode in the Target pane.
    2. Obtain the complete XPath of the element Catalog/Products/Product/ProductId in the Source pane.
    3. Double-click Custom XSLT icon to open the properties pane and provide following XSLT.
      <xsl:template xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
          <ItemCode>
              <xsl:value-of select="/Catalog/Products/Product/ProductId"/>
          </ItemCode>
      </xsl:template>
      


  2. Click the Test Model tab. The Test Model tab with the source XML is displayed.
  3. In the Source XML pane, type appropriate values for the source elements. Alternatively, you can click Fill Source Data, which assigns sample string values to the source elements. Make changes to these values, if required. The elements in the Source XML pane are populated with the specified values.
  4. Click Transform to start the data transformation process.
  5. The data is transformed and displayed in the Transformed XML pane indicating completion of the process.
Test Source XML
<Catalog>
    <Products>
        <Product>
            <ProductId>1010</ProductId>
            <ProductDescription>Funiture</ProductDescription>
        </Product>
        <Product>
            <ProductId>1020</ProductId>
            <ProductDescription>clothing</ProductDescription>
        </Product>
    </Products>
</Catalog>
Generated Target XML
<PurchaseOrder>
    <Items>
        <Item>
            <ItemCode>1010</ItemCode>
        </Item>
    </Items>
</PurchaseOrder>

Scenario 3: Creating repeated target elements when Source element is selected and an Absolute XPath is provided

This scenario is similar to scenario 2 with a link to the source element is provided additionally.

Consider the Source Schema and Target Schema that are given in Scenario 2.

  1. Do the following to map the elements between the source and target templates using the Custom XSLT function:
    1. Select Custom XSLT and click PurchaseOrder/Items/Item/ItemCode in the Target pane.
    2. Select Catalog/Products/Product/ProductId from the Source pane and click Custom XSLT.
    3. Get XPath of the source element Catalog/Products/Product/ProductId to prepare the XSLT.
  2. Double-click the Custom XSLT icon to open the properties pane and provide the following XSLT:
    <xsl:template xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <ItemCode>
            <xsl:value-of select="/Catalog/Products/Product/ProductId"/>
        </ItemCode>
    </xsl:template>
    
  3. Click the Test Model tab. The Test Model tab with the source XML is displayed.
  4. In the Source XML pane, type appropriate values for the source elements. Alternatively, you may click Fill Source Data , which assigns sample string values to the source elements. Make changes to these values, if required. The elements in the Source XML pane are populated with the specified values.
  5. Click Transform to start the data transformation process.
  6. The data is transformed and displayed in the Transformed XML pane indicating the completion of the process.
Test Source XML
<Catalog>
    <Products>
        <Product>
            <ProductId>1010</ProductId>
            <ProductDescription>Funiture</ProductDescription>
        </Product>
        <Product>
            <ProductId>1020</ProductId>
            <ProductDescription>clothing</ProductDescription>
        </Product>
    </Products>
</Catalog>
Generated Target XML
<PurchaseOrder>
    <Items>
        <Item>
            <ItemCode>1010</ItemCode>
        </Item>
        <Item>
            <ItemCode>1010</ItemCode>
        </Item>
    </Items>
</PurchaseOrder>

Scenario 4 : Creating repeated target elements when the Source element is not selected but a direct link is provided for other element

Consider the Source Schema and Target Schema that are used in Scenario 2.

  1. Do the following to map the elements between the source and target templates using the Custom XSLT function:
    1. Select Catalog/Products/Product/ProductId from Source pane and click on PurchaseOrder/Items/Item/ItemCode in the Target pane. A direct mapping is created.
    2. Select Custom XSLT and click PurchaseOrder/Items/Item/ItemDescription in the Target pane. Note: Ensure to provide the complete XPath of the source element in the XSLT as you do not link to the Source directly.
    3. Double-click Custom XSLT icon to open the properties pane and provide following XSLT:
      <xsl:template xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
          <ItemDescription>
              <xsl:value-of select="/Catalog/Products/Product/ProductDescription"/>
          </ItemDescription>
      </xsl:template>
      
  2. Click the Test Model tab. The Test Model tab with the source XML is displayed.
  3. In the Source XML pane, type appropriate values for the source elements. Alternatively, you may click Fill Source Data, which assigns sample string values to the source elements. Make changes to these values, if required. The elements in the Source XML pane are populated with the specified values.
  4. Click Transform to start the data transformation process.
  5. The data is transformed and displayed in the Transformed XML pane indicating the completion of the process. The transformed XML is similar to the transformed XML in Scenario 2.
Test Source XML
<Catalog>
    <Products>
        <Product>
            <ProductId>1010</ProductId>
            <ProductDescription>Furniture</ProductDescription>
        </Product>
        <Product>
            <ProductId>1020</ProductId>
            <ProductDescription>Clothing</ProductDescription>
        </Product>
    </Products>
</Catalog>
Generated Target XML
<PurchaseOrder>
    <Items>
        <Item>
            <ItemCode>1010</ItemCode>
            <ItemDescription>Furniture</ItemDescription>
        </Item>
        <Item>
            <ItemCode>1020</ItemCode>
            <ItemDescription>Furniture</ItemDescription>
        </Item>
    </Items>
</PurchaseOrder>

Scenario 5 : Creating repeated target elements when the Source element is selected and a relative XPath is provided

Consider the Source Schema and Target Schema that are used in Scenario 2.

  1. Do the following to map the elements between the source and target templates using the Custom XSLT function:
    1. Select Catalog/Products/Product/ProductId from Source pane and click PurchaseOrder/Items/Item/ItemCode in the Target pane. A direct mapping is created.
    2. Select Custom XSLT and click PurchaseOrder/Items/Item/ItemDescription in the Target pane.
    3. Select Catalog/Products/Product/ProductDescription and click Custom XSLT. The source element is now linked with the Custom XSLT.
    4. In the XSLT, provide the XPath from the Source; that is, the relative path to the source element. The Source element is Product and the XPath is considered from there; that is, ProductDescription.
    5. Double-click Custom XSLT icon to open the properties pane and provide following XSLT:
      <xsl:template xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
          <ItemDescription>
              <xsl:value-of select="ProductDescription"/>
          </ItemDescription>
      </xsl:template>
      
  2. Click the Test Model tab. The Test Model tab with the source XML is displayed.
  3. In the Source XML pane, type appropriate values for the source elements. Alternatively, you may click Fill Source Data, which assigns sample string values to the source elements. Make changes to these values, if required. The elements in the Source XML pane are populated with the specified values.
  4. Click Transform to start the data transformation process.
  5. The data is transformed and displayed in the Transformed XML pane indicating the completion of the process. The transformed XML is similar to the transformed XML in Scenario 2.
Test Source XML
<Catalog>
    <Products>
        <Product>
            <ProductId>1010</ProductId>
            <ProductDescription>Furniture</ProductDescription>
        </Product>
        <Product>
            <ProductId>1020</ProductId>
            <ProductDescription>Clothing</ProductDescription>
        </Product>
    </Products>
</Catalog>
Generated Target XML
<PurchaseOrder xmlns="">
    <Items>
        <Item>
            <ItemCode>1010</ItemCode>
            <ItemDescription>Furniture</ItemDescription>
        </Item>
        <Item>
            <ItemCode>1020</ItemCode>
            <ItemDescription>Clothing</ItemDescription>
        </Item>
    </Items>
</PurchaseOrder>

Scenario 6 : Creating a Target element based on the Source elements value without the Source element selected directly

Consider the following Source schema and Target Schema for this Scenario.

Source Schema
<element name="Orders" xmlns="http://www.w3.org/2001/XMLSchema">
    <complexType>
        <sequence>
            <element maxOccurs="unbounded" minOccurs="0" name="Order">
                <complexType>
                    <sequence>
                        <xsd:element name="CustomerID" type="xsd:string" xmlns:xsd="http://www.w3.org/2001/XMLSchema"/>
                        <element maxOccurs="unbounded" minOccurs="0" name="date">
                            <complexType>
                                <sequence>
                                    <xsd:element name="type"
                                    type="xsd:string" xmlns:xsd="http://www.w3.org/2001/XMLSchema"/>
                                    <xsd:element name="value"
                                    type="xsd:string" xmlns:xsd="http://www.w3.org/2001/XMLSchema"/>
                                </sequence>
                            </complexType>
                        </element>
                    </sequence>
                </complexType>
            </element>
        </sequence>
    </complexType>
</element>

Target Schema
<element name="PurchaseOrder" xmlns="http://www.w3.org/2001/XMLSchema">
    <complexType>
        <sequence>
            <element name="OrderId" type="xs:string" xmlns:xs="http://www.w3.org/2001/XMLSchema"/>
            <element name="Dates">
                <complexType>
                    <sequence>
                        <element minOccurs="0" name="OrderDate"
                            type="xs:string"
                            xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsd="http://www.w3.org/2001/XMLSchema"/>
                        <element minOccurs="0" name="BillingDate"
                            type="xs:string"
                            xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsd="http://www.w3.org/2001/XMLSchema"/>
                        <element minOccurs="0" name="DeliveryDate"
                            type="xs:string"
                            xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsd="http://www.w3.org/2001/XMLSchema"/>
                    </sequence>
                </complexType>
            </element>
        </sequence>
    </complexType>
</element>
  1. Do the following to map the elements between the source and target templates using the Custom XSLT function:
    1. Select Custom XSLT and click /PurchaseOrder/Dates/OrderDate in the Target pane.
    2. Provide the XPath of the source elements in the XSLT as required to create target nodes.
    3. Double-click Custom XSLT icon to open the properties pane and provide following XSLT: Note: The variable orderpath is created and used throughout the XSLT and xsl:if with a condition is used.

      <xsl:template xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
          <xsl:variable name="orderpath" select="/Orders/Order"/>
          <OrderDate>
              <xsl:value-of select="$orderpath/date[type='Order']/value"/>
          </OrderDate>
          <xsl:if test="$orderpath/date[type='Billing']">
              <BillingDate>
                  <xsl:value-of select="$orderpath/date[type='Billing']/value"/>
              </BillingDate>
          </xsl:if>
          <xsl:if test="$orderpath/date[type='Delivery']">
              <DeliveryDate>
                  <xsl:value-of select="$orderpath/date[type='Delivery']/value"/>
              </DeliveryDate>
          </xsl:if>
      </xsl:template>
      
  2. Click the Test Model tab. The Test Model tab with the source XML is displayed.
  3. In the Source XML pane, type the appropriate values for the source elements. Alternatively, you may click Fill Source Data , which assigns sample string values to the source elements. Make changes to these values, if required. The elements in the Source XML pane are populated with the specified values.
  4. Click Transform to start the data transformation process.
  5. The data is transformed and displayed in the Transformed XML pane indicating the completion of the process. The transformed XML is similar to the transformed XML in Scenario 2.
Test Source XML
<Orders>
    <Order>
        <CustomerID>GREAL</CustomerID>
        <date>
            <type>Order</type>
            <value>09/07/2013</value>
        </date>
        <date>
            <type>Billing</type>
            <value>09/07/2013</value>
        </date>
        <date>
            <type>Shipping</type>
            <value>09/07/2013</value>
        </date>
    </Order>
</Orders>
Generated Target XML
<PurchaseOrder>
    <Dates>
        <OrderDate>09/07/2013</OrderDate>
        <BillingDate>09/07/2013</BillingDate>
    </Dates>
</PurchaseOrder>


The following actions on the Custom XSLT function are not allowed:

  • Custom XSLT does not allow mapping to or mapping from other function blocks.
  • Custom XSLT can be mapped from one Source Element only. Mapping to multiple source elements is not allowed.
  • The XPaths defined in custom XSLT may be invalid when a second schema is added to the Source or Target tree.

.